<template>
	<view class="container">
		<view v-if="freshList.length===0" style="color: #CCCCCC;text-align: center;width: 100%;height: 500upx;line-height: 500upx;font-size: 32upx;"> 暂无数据</view>
		<view v-else>
			
		
		<view class="un-top">
			<image :src="img+'/top/exchange.jpg'" mode="aspectFill"></image>
		</view>
		
		<view class="f-header m-t" >
			<view class="tit-box">
				<text class="tit">优品精选</text>
			</view>
		</view>
		
		<view class="tehui-section">
			<view 
				v-for="(item, index) in freshList" :key="index"
				class="tehui-item"
				
			>
				<view class="un-renimage-wrapper">
					<image :src="img+item.THUMB" mode="aspectFill"></image>
				</view>
				<view >
					<text class="un-rentitle clamp">{{item.NAME}}</text>
					<text class="un-rentit2 title2 clamp">{{item.SHORTINFO}}</text>
					<!-- <text class="un-renprice">特惠价：￥{{item.SALEPRICE}}</text> -->
					<text class="un-renprice" v-if="!item.MULTIPAY">特惠价：¥{{item.SALEPRICE}}</text>
					
					<text class="un-renprice" v-if="item.MULTIPAY==2&&item.OPPOINT!=0">积分:{{item.OPPOINT}}</text>
					<text class="un-renprice" v-if="item.MULTIPAY==2&&item.OPDEDU!=0">抵扣券:{{item.OPDEDU}}</text>
					<text class="un-renprice" v-if="item.MULTIPAY==2&&item.OPCOUPON!=0">惠券:{{item.OPCOUPON}}</text>
					
					<text class="un-renprice" v-if="item.MULTIPAY==3&&item.MUCHSELLERPRICE!=0">¥{{item.MUCHSELLERPRICE}}</text>
					<text class="un-renprice" v-if="item.MULTIPAY==3&&item.MUCHSELLERPRICE!=0&&item.MPPOINT!=0">+</text>
					<text class="un-renprice" v-if="item.MULTIPAY==3&&item.MPPOINT!=0">积分:{{item.MPPOINT}}</text>
					<text class="un-renprice" v-if="item.MULTIPAY==3&&(item.MUCHSELLERPRICE!=0||item.MPPOINT!=0)&&item.MPDEDU!=0">+</text>
					<text class="un-renprice" v-if="item.MULTIPAY==3&&item.MPDEDU!=0">抵扣券:{{item.MPDEDU}}</text>
					<text class="un-renprice" v-if="item.MULTIPAY==3&&(item.MUCHSELLERPRICE!=0||item.MPPOINT!=0||item.MPDEDU!=0)&&item.MPCOUPON!=0">+</text>
					<text class="un-renprice" v-if="item.MULTIPAY==3&&item.MPCOUPON!=0">惠券:{{item.MPCOUPON}}</text>
					<text class="un-rentit2 title2 clamp">已售{{item.SALECOUNT}}</text>
				</view>
				<text class="un-huangkuang" @click="navToDetailPage(item)">查看详情</text>
			</view>
		</view>
		</view>
	</view>
	
	
</template>

<script>
	
	export default {
		components: {
		},
		data() {
			return {
				goodsList: [],
				freshList:[],
				img:''
			}
		},
		onNavigationBarButtonTap() {  
		    console.log("点击了自定义按钮");  
		},
		onLoad() {
				this.loadData();
				this.img = getApp().globalData.imageAddress
				this.loadfresh();
			uni.startPullDownRefresh();
		},
		onPullDownRefresh() {
			console.log('refresh');
			setTimeout(function () {
				uni.stopPullDownRefresh();
			}, 1000);
		},
		methods: {  
			async loadData() {
			let goodsList = await this.$api.json('goodsList');
			this.goodsList = goodsList || [];
			},
			
			//加载新鲜好物
			async loadfresh(){
					//加载信息
				this.$http.post("/goods/fresh",{
					SIGNATURE : uni.getStorageSync("SIGNATURE"),
					GP: '7'
				}).then((e)=>{
					// this.freshList =  e.data.OBJECT
					e.data.OBJECT.map(item=>{
						if(item.ID){
								this.freshList.push(item)
						}
					})
				}).catch((err)=>{
					console.log("请求超时",err);
				})
				
			},
		
			//详情页
			navToDetailPage(item) {
				if(item.MULTIPAY){
					let ids=item.GOODID;
					let sid=item.ID;
					uni.navigateTo({
						url: `/pages/product/productExchange?id=${ids}&sid=${sid}`
					})
				}else{
					let id = item.ID;
					uni.navigateTo({
						url: `/pages/product/product?id=${id}`
					})
				}
			}
			
		},
		
	}
</script>

<style lang="scss">
	page{
		background-color: #F5F5F5;
	}
	.un-top{
		width: 100%;
		height: 310upx;
		background: #fff;
		image{
			width:100%;
			height: 100%; 
		}
	}
	
	.f-header{
		display:flex;
		align-items:center;
		margin-top: 30upx;
		height: 100upx;
		padding: 6upx 60upx 8upx;
		background: #fff;
		border-top: #F2F2F2 1upx solid;
		image{
			flex-shrink: 0;
			width: 80upx;
			height: 80upx;
			margin-right: 20upx;
		}
		.tit-box{
			flex: 1;
			display: flex;
			flex-direction: column;
		}
		.tit{
			font-size: 26upx;
			color: $font-color-dark;
			line-height: 1.3;
		}
		
	}
	
	
	.tehui-section{
		display:flex;
		flex-wrap:wrap;
		padding: 0 30upx;
		background: #fff;
		
		
		.tehui-item{
			margin-left: 15upx;
			position: relative;
			display:flex;
			flex-direction: row;
			width: 100%;
			border-top: #F2F2F2 1upx solid;
		}
		.un-renimage-wrapper{
			margin: 20upx 50upx 20upx 45upx;
			width: 140upx;
			height: 140upx;
			border-radius: 3px;
			overflow: hidden;
			image{
				width: 100%;
				height: 100%;
				opacity: 1;
			}
		}
		.un-rentitle{
			margin-top: 20upx;
			width: 400upx;
			font-size: 24upx;
			color: $font-color-dark;
			line-height: 50upx;
			overflow: hidden;
		}
		.un-renprice{
			width: 400upx;
			font-size: 24upx;
			color: $uni-color-primary;
			line-height: 1;
			line-height: 50upx;
		}
		.un-rentit2{
			width: 400upx;
			font-size: 24upx;
			color: $font-color-light;
			line-height: 25upx;
		}
		.un-huangkuang{
			    position: absolute;
				top: 115upx;
				right: 50upx;
				width: 60px;
				height: 20px;
				background: inherit;
				background-color: rgba(255, 255, 255, 0);
				box-sizing: border-box;
				border-width: 1px;
				border-style: solid;
				border-color: rgba(241, 151, 54, 1);
				border-radius: 0px;
				border-bottom-left-radius: 0px;
				-moz-box-shadow: none;
				-webkit-box-shadow: none;
				box-shadow: none;
				font-family: '微软雅黑';
				font-weight: 404;
				font-style: normal;
				font-size: 11px;
				color: #F19736;
				text-align: center;
				
		}
	}
</style>
